<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.5"/>
<title>pynetconf: Example Applications</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="libnetconf-logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">pynetconf
   </div>
   <div id="projectbrief">libnetconf wrapper for Python</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('apps.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Example Applications </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Example applications using the libnetconf Python API are located in the source tree inside the <code>libnetconf/python/examples/</code> directory.</p>
<h1><a class="anchor" id="apps-get"></a>
get.py</h1>
<p>Simple client-side application printing the result of the NETCONF &lt;get&gt; operation. </p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;$ ./get.py localhost -f <span class="stringliteral">&quot;&lt;nacm&gt;&lt;rule-list/&gt;&lt;/nacm&gt;&quot;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;&lt;nacm xmlns=<span class="stringliteral">&quot;urn:ietf:params:xml:ns:yang:ietf-netconf-acm&quot;</span>&gt;</div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;  &lt;rule-list&gt;</div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;    &lt;name&gt;permit-all&lt;/name&gt;</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;    &lt;group&gt;users&lt;/group&gt;</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;    &lt;rule&gt;</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;      &lt;name&gt;permit-all-rule&lt;/name&gt;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;      &lt;module-name&gt;*&lt;/module-name&gt;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;      &lt;access-operations&gt;*&lt;/access-operations&gt;</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;      &lt;action&gt;permit&lt;/action&gt;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;    &lt;/rule&gt;</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;  &lt;/rule-list&gt;</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;&lt;/nacm&gt;</div>
</div><!-- fragment --><h1><a class="anchor" id="apps-server"></a>
server.py</h1>
<p>Very simple (4 LOC) NETCONF server <code>server.py</code> is alternative to the Netopeer's <a href="https://code.google.com/p/netopeer/wiki/SingleLevelServer">single-layer server</a>.</p>
<p>To see, how the server interacts with a client, you can run it from the command line and communicate with the server interactively (if you don't understand the following lines, and you want to, read <a href="http://tools.ietf.org/html/rfc6241">RFC 6241</a> and <a href="http://tools.ietf.org/html/rfc6242">RFC 6242</a>): </p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;$ ./server.py </div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;&lt;?xml version=<span class="stringliteral">&quot;1.0&quot;</span> encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>?&gt;</div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;&lt;hello xmlns=<span class="stringliteral">&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot;</span>&gt;</div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;  &lt;capabilities&gt;</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;    &lt;capability&gt;urn:ietf:params:netconf:base:1.0&lt;/capability&gt;</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;    &lt;capability&gt;urn:ietf:params:netconf:base:1.1&lt;/capability&gt;</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;    &lt;capability&gt;urn:ietf:params:netconf:capability:writable-running:1.0&lt;/capability&gt;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;    ...</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;  &lt;/capabilities&gt;</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;  &lt;session-id&gt;31059&lt;/session-id&gt;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;&lt;/hello&gt;</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;]]&gt;]]&gt;&lt;?xml version=<span class="stringliteral">&quot;1.0&quot;</span> encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>?&gt;</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;&lt;hello xmlns=<span class="stringliteral">&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot;</span>&gt;</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;  &lt;capabilities&gt;</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;    &lt;capability&gt;urn:ietf:params:netconf:base:1.0&lt;/capability&gt;</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;  &lt;/capabilities&gt;</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;&lt;/hello&gt;]]&gt;]]&gt;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;&lt;?xml version=<span class="stringliteral">&quot;1.0&quot;</span> encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>?&gt;</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;&lt;rpc xmlns=<span class="stringliteral">&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot;</span> message-id=<span class="stringliteral">&quot;1&quot;</span>&gt;</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;  &lt;close-session/&gt;</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;&lt;/rpc&gt;]]&gt;]]&gt;</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;&lt;?xml version=<span class="stringliteral">&quot;1.0&quot;</span> encoding=<span class="stringliteral">&quot;UTF-8&quot;</span>?&gt;</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;&lt;rpc-reply xmlns=<span class="stringliteral">&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot;</span> message-id=<span class="stringliteral">&quot;1&quot;</span>&gt;</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;  &lt;ok/&gt;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;&lt;/rpc-reply&gt;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;]]&gt;]]&gt;</div>
</div><!-- fragment --><p>However, the more usual way how to use it, is to set your SSH server to run it as its <code>netconf</code> SSH Subsystem. In this case, the server is started automatically when client connects to the host. To configure your SSH server this way, add the following line to the <code>/etc/ssh/sshd_config</code> file. </p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;Subsystem netconf /path/to/server.pl</div>
</div><!-- fragment --><p>Also remember to correctly set the port where the SSH server listens. By default, it listens on port 22, but NETCONF has assigned port 830 and the most of clients use it by default.</p>
<p>And finally, don't forget to make the SSH server reload the changed configuration. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Thu Nov 6 2014 10:42:36 for pynetconf by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.5 </li>
  </ul>
</div>
</body>
</html>
